home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / AmigaSystem / AmiStart / ModulesSDK.lha / source / StartUp.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-19  |  10.6 KB  |  318 lines

  1. /*
  2. **      $VER: StartUp.c 37.31 (18.3.98)
  3. **
  4. **      Library startup-code and function table definition
  5. **
  6. **      (C) Copyright 1996-98 Andreas R. Kleinert
  7. **      All Rights Reserved.
  8. **
  9. **        modified by adding functions by Darius Brewka
  10. */
  11.  
  12. #define __USE_SYSBASE        // perhaps only recognized by SAS/C
  13.  
  14. #include <exec/types.h>
  15. #include <exec/memory.h>
  16. #include <exec/libraries.h>
  17. #include <exec/execbase.h>
  18. #include <exec/resident.h>
  19. #include <exec/initializers.h>
  20.  
  21.  
  22. #ifdef __MAXON__
  23. #include <pragma/exec_lib.h>
  24. #include <linkerfunc.h>
  25. #else
  26. #include <proto/exec.h>    // all other compilers
  27. #endif
  28. #include "compiler.h"
  29.  
  30. #include "amistart_modulebase.h"
  31.  
  32. #include "ModuleFuncs.h"
  33.  
  34.  
  35. extern ULONG __saveds __stdargs L_OpenLibs(struct AmiStartModuleBase *AmiStartModuleBase);
  36. extern void  __saveds __stdargs L_CloseLibs(void);
  37.  
  38. struct AmiStartModuleBase * __saveds ASM InitLib( register __a6 struct ExecBase    *sysbase GNUCREG(a6),
  39.                                            register __a0 SEGLISTPTR          seglist GNUCREG(a0),
  40.                                            register __d0 struct AmiStartModuleBase *exb     GNUCREG(d0));
  41. struct AmiStartModuleBase * __saveds ASM OpenLib( register __a6 struct AmiStartModuleBase *AmiStartModuleBase GNUCREG(a6));
  42. SEGLISTPTR __saveds ASM CloseLib( register __a6 struct AmiStartModuleBase *AmiStartModuleBase GNUCREG(a6));
  43. SEGLISTPTR __saveds ASM ExpungeLib( register __a6 struct AmiStartModuleBase *exb GNUCREG(a6));
  44. ULONG ASM ExtFuncLib(void);
  45.  
  46.  
  47. /* ----------------------------------------------------------------------------------------
  48.    ! LibStart:
  49.    !
  50.    ! If someone tries to start a library as an executable, it must return (LONG) -1
  51.    ! as result. That's what we are doing here.
  52.    ---------------------------------------------------------------------------------------- */
  53.  
  54. LONG ASM LibStart(void)
  55. {
  56.  return(-1);
  57. }
  58.  
  59.  
  60. /* ----------------------------------------------------------------------------------------
  61.    ! Function and Data Tables:
  62.    !
  63.    ! The function and data tables have been placed here for traditional reasons.
  64.    ! Placing the RomTag structure before (-> LibInit.c) would also be a good idea,
  65.    ! but it depends on whether you would like to keep the "version" stuff separately.
  66.    ---------------------------------------------------------------------------------------- */
  67.  
  68. extern APTR FuncTab [];
  69. /*  extern struct MyDataInit DataTab;  */
  70. extern DataTab; /* DICE fix */
  71.                                   /* Instead you may place ROMTag + Datatab directly, here */
  72.                                   /* (see LibInit.c). This may fix "Installer" version     */
  73.                                   /* checking problems, too - try it.                      */
  74.  
  75. struct InitTable                       /* do not change */
  76. {
  77.  ULONG              LibBaseSize;
  78.  APTR              *FunctionTable;
  79.  struct MyDataInit *DataTable;
  80.  APTR               InitLibTable;
  81. } InitTab =
  82. {
  83.  (ULONG)               sizeof(struct AmiStartModuleBase),
  84.  (APTR              *) &FuncTab[0],
  85.  (struct MyDataInit *) &DataTab,
  86.  (APTR)                InitLib
  87. };
  88.  
  89. APTR FuncTab [] =
  90. {
  91.  (APTR) OpenLib,
  92.  (APTR) CloseLib,
  93.  (APTR) ExpungeLib,
  94.  (APTR) ExtFuncLib,
  95.  
  96.  (APTR) GetModuleInfo,  /* add your own functions here */
  97.  (APTR) InitModule,
  98.  (APTR) NextModuleData,
  99.  (APTR) DisposeModule,
  100.  (APTR) GetModuleName,
  101.  (APTR) GetModuleIcon,
  102.  (APTR) GetModuleTool,
  103.  (APTR) GetModuleUserData,
  104.  (APTR) GetModuleDescription,
  105.  (APTR) OpenModule,
  106.  (APTR) CloseModule,
  107.  (APTR) DoModuleCommand,
  108.  (APTR) HitModule,
  109.  (APTR) GetModuleFlags,
  110.  (APTR) GetSpecialInfo,
  111.  (APTR) GetModuleConfig,
  112.  
  113.  (APTR) ((LONG)-1),
  114. };
  115.  
  116.  
  117. extern struct AmiStartModuleBase *AmiStartModuleBase;
  118.  
  119. /* ----------------------------------------------------------------------------------------
  120.    ! InitLib:
  121.    !
  122.    ! This one is single-threaded by the Ramlib process. Theoretically you can do, what
  123.    ! you like here, since you have full exclusive control over all the library code and data.
  124.    ! But due to some bugs in Ramlib V37-40, you can easily cause a deadlock when opening
  125.    ! certain libraries here (which open other libraries, that open other libraries, that...)
  126.    !
  127.    ---------------------------------------------------------------------------------------- */
  128.  
  129. struct AmiStartModuleBase * __saveds ASM InitLib( register __a6 struct ExecBase      *sysbase GNUCREG(a6),
  130.                                            register __a0 SEGLISTPTR            seglist GNUCREG(a0),
  131.                                            register __d0 struct AmiStartModuleBase   *exb     GNUCREG(d0))
  132. {
  133.  AmiStartModuleBase = exb;
  134.  
  135.  AmiStartModuleBase->exb_SysBase = sysbase;
  136.  AmiStartModuleBase->exb_SegList = seglist;
  137.  
  138.  if(L_OpenLibs(AmiStartModuleBase)) return(AmiStartModuleBase);
  139.  
  140.  L_CloseLibs();
  141.  
  142.   {
  143.    ULONG negsize, possize, fullsize;
  144.    UBYTE *negptr = (UBYTE *) AmiStartModuleBase;
  145.  
  146.    negsize  = AmiStartModuleBase->exb_LibNode.lib_NegSize;
  147.    possize  = AmiStartModuleBase->exb_LibNode.lib_PosSize;
  148.    fullsize = negsize + possize;
  149.    negptr  -= negsize;
  150.  
  151.    FreeMem(negptr, fullsize);
  152.  
  153.    #ifdef __MAXON__
  154.    CleanupModules();
  155.    #endif
  156.   }
  157.  
  158.  return(NULL);
  159. }
  160.  
  161. /* ----------------------------------------------------------------------------------------
  162.    ! OpenLib:
  163.    !
  164.    ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a Wait() call
  165.    ! would break this Forbid/Permit(), you are not allowed to start any operations that
  166.    ! may cause a Wait() during their processing. It's possible, that future OS versions
  167.    ! won't turn the multi-tasking off, but instead use semaphore protection for this
  168.    ! function.
  169.    !
  170.    ! Currently you only can bypass this restriction by supplying your own semaphore
  171.    ! mechanism.
  172.    ---------------------------------------------------------------------------------------- */
  173.  
  174. struct AmiStartModuleBase * __saveds ASM OpenLib( register __a6 struct AmiStartModuleBase *AmiStartModuleBase GNUCREG(a6))
  175. {
  176.  #ifdef __MAXON__
  177.  GetBaseReg();
  178.  InitModules();
  179.  #endif
  180.  
  181.  AmiStartModuleBase->exb_LibNode.lib_OpenCnt++;
  182.  
  183.  AmiStartModuleBase->exb_LibNode.lib_Flags &= ~LIBF_DELEXP;
  184.  
  185.  return(AmiStartModuleBase);
  186. }
  187.  
  188. /* ----------------------------------------------------------------------------------------
  189.    ! CloseLib:
  190.    !
  191.    ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a Wait() call
  192.    ! would break this Forbid/Permit(), you are not allowed to start any operations that
  193.    ! may cause a Wait() during their processing. It's possible, that future OS versions
  194.    ! won't turn the multi-tasking off, but instead use semaphore protection for this
  195.    ! function.
  196.    !
  197.    ! Currently you only can bypass this restriction by supplying your own semaphore
  198.    ! mechanism.
  199.    ---------------------------------------------------------------------------------------- */
  200.  
  201. SEGLISTPTR __saveds ASM CloseLib( register __a6 struct AmiStartModuleBase *AmiStartModuleBase GNUCREG(a6))
  202. {
  203.  AmiStartModuleBase->exb_LibNode.lib_OpenCnt--;
  204.  
  205.  if(!AmiStartModuleBase->exb_LibNode.lib_OpenCnt)
  206.   {
  207.    if(AmiStartModuleBase->exb_LibNode.lib_Flags & LIBF_DELEXP)
  208.     {
  209.      return( ExpungeLib(AmiStartModuleBase) );
  210.     }
  211.   }
  212.  
  213.  return(NULL);
  214. }
  215.  
  216. /* ----------------------------------------------------------------------------------------
  217.    ! ExpungeLib:
  218.    !
  219.    ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a Wait() call
  220.    ! would break this Forbid/Permit(), you are not allowed to start any operations that
  221.    ! may cause a Wait() during their processing. It's possible, that future OS versions
  222.    ! won't turn the multi-tasking off, but instead use semaphore protection for this
  223.    ! function.
  224.    !
  225.    ! Currently you only could bypass this restriction by supplying your own semaphore
  226.    ! mechanism - but since expunging can't be done twice, one should avoid it here.
  227.    ---------------------------------------------------------------------------------------- */
  228.  
  229. SEGLISTPTR __saveds ASM ExpungeLib( register __a6 struct AmiStartModuleBase *exb GNUCREG(a6))
  230. {
  231.  struct AmiStartModuleBase *AmiStartModuleBase = exb;
  232.  SEGLISTPTR seglist;
  233.  
  234.  if(!AmiStartModuleBase->exb_LibNode.lib_OpenCnt)
  235.   {
  236.    ULONG negsize, possize, fullsize;
  237.    UBYTE *negptr = (UBYTE *) AmiStartModuleBase;
  238.  
  239.    seglist = AmiStartModuleBase->exb_SegList;
  240.  
  241.    Remove((struct Node *)AmiStartModuleBase);
  242.  
  243.    L_CloseLibs();
  244.  
  245.    negsize  = AmiStartModuleBase->exb_LibNode.lib_NegSize;
  246.    possize  = AmiStartModuleBase->exb_LibNode.lib_PosSize;
  247.    fullsize = negsize + possize;
  248.    negptr  -= negsize;
  249.  
  250.    FreeMem(negptr, fullsize);
  251.  
  252.    #ifdef __MAXON__
  253.    CleanupModules();
  254.    #endif
  255.  
  256.    return(seglist);
  257.   }
  258.  
  259.  AmiStartModuleBase->exb_LibNode.lib_Flags |= LIBF_DELEXP;
  260.  
  261.  return(NULL);
  262. }
  263.  
  264. /* ----------------------------------------------------------------------------------------
  265.    ! ExtFunct:
  266.    !
  267.    ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a Wait() call
  268.    ! would break this Forbid/Permit(), you are not allowed to start any operations that
  269.    ! may cause a Wait() during their processing. It's possible, that future OS versions
  270.    ! won't turn the multi-tasking off, but instead use semaphore protection for this
  271.    ! function.
  272.    !
  273.    ! Currently you only can bypass this restriction by supplying your own semaphore
  274.    ! mechanism - but since this function currently is unused, you should not touch
  275.    ! it, either.
  276.    ---------------------------------------------------------------------------------------- */
  277.  
  278. ULONG ASM ExtFuncLib(void)
  279. {
  280.  return(NULL);
  281. }
  282.  
  283. struct AmiStartModuleBase *AmiStartModuleBase = NULL;
  284.  
  285.  
  286. /* ----------------------------------------------------------------------------------------
  287.    ! __SASC stuff:
  288.    !
  289.    ! This is only for SAS/C - its intention is to turn off internal CTRL-C handling
  290.    ! for standard C functions and to avoid calls to exit() et al.
  291.    ---------------------------------------------------------------------------------------- */
  292.  
  293. #ifdef __SASC
  294.  
  295. #ifdef ARK_OLD_STDIO_FIX
  296.  
  297. ULONG XCEXIT       = NULL; /* These symbols may be referenced by    */
  298. ULONG _XCEXIT      = NULL; /* some functions of sc.lib, but should  */
  299. ULONG ONBREAK      = NULL; /* never be used inside a shared library */
  300. ULONG _ONBREAK     = NULL;
  301. ULONG base         = NULL; /* Note, that XCEXIT/ONBREAK actually    */
  302. ULONG _base        = NULL; /* should have been defined as functions */
  303. ULONG ProgramName  = NULL; /* and not as ULONGs...                  */
  304. ULONG _ProgramName = NULL;
  305. ULONG StackPtr     = NULL;
  306. ULONG _StackPtr    = NULL;
  307. ULONG oserr        = NULL;
  308. ULONG _oserr       = NULL;
  309. ULONG OSERR        = NULL;
  310. ULONG _OSERR       = NULL;
  311.  
  312. #endif /* ARK_OLD_STDIO_FIX */
  313.  
  314. void __regargs __chkabort(void) { }  /* a shared library cannot be    */
  315. void __regargs _CXBRK(void)     { }  /* CTRL-C aborted when doing I/O */
  316.  
  317. #endif /* __SASC */
  318.